home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-05 | 3.5 KB | 169 lines | [TEXT/MSET] |
- \ DICTIONARY CLASS Reese Warner 4/85
- \ Useful for symbol tables, et. al.
-
- 0 -> dlevel
-
-
- :class DICTELT super{ string }
- record
- { objHandle OBJHDL \ Handle to the object associated with the string.
- }
-
- :m PUTOBJHDL: put: objHdl ;m
- :m GETOBJ: obj: objHdl ;m
- :m RELEASE:
- release: super
- nil?: objHdl ?EXIT
- obj: objHdl release: ** release: objHdl ;m
-
- :m PRINT: 4 spaces print: super 3 spaces obj: objHdl print: ** ;m
-
- ;class
-
-
- objPtr HLOBJ class_is handleList
- objPtr DEOBJ class_is dictElt
-
-
- :class DICTIONARY super{ handleArray }
-
- private
-
- \ SEARCHLIST - does the main work of methods ENTER & QUERY. Intended to be
- \ a private method for class DICTIONARY. Searchs the handleList object
- \ HLobj for a dictElt object matching the given string. If found, returns
- \ the matching dictElt object and true, otherwise just false.
-
- :m SEARCHLIST: { HLob strObj -- DEobj T | -- F }
- HLob -> HLobj
- BEGIN each: HLobj
- WHILE
- ( obj addr ) -> DEobj
- get: [ strObj ] get: DEobj s=
- IF unEach: HLobj DEobj true EXIT THEN
- REPEAT
- false ;m
-
- public
-
- \ QUERY - returns pointer to the object associated with strObj in the
- \ dictionary. If string is not found, then nilP is returned.
-
- :m QUERY: { strObj \ idx -- ^obj }
-
- get: [ strObj ] str255 wHash limit: self mod -> idx
- idx select: self
- nil?: self IF nilP EXIT THEN
- obj: self -> HLobj
- size: HLobj NIF nilP EXIT THEN
- HLobj strObj searchList: self
- IF
- -> DEobj
- getObj: DEobj
- ELSE
- nilP
- THEN
- unlock: self ;m
-
-
- \ ENTER - puts the string and value into the dictionary. If the string is
- \ already in the dictionary then it changes the value to the new value.
-
- :m ENTER: { hdlObj strObj \ idx -- }
-
- get: [ strObj ] str255 wHash limit: super mod -> idx
- idx select: self
- nil?: self
- IF ( Need new handleList object )
- ['] handleList newObj: self obj: self -> HLobj
- ['] dictElt newObj: HLobj obj: HLobj -> DEobj
- strObj ->: DEobj
- get: [ hdlObj ] putObjHdl: DEobj
- ELSE
- obj: self -> HLobj
- HLobj strObj searchList: self
- IF ( In already - change value )
- -> DEobj
- get: [ hdlObj ] putObjHdl: DEobj
- ELSE
- ['] dictElt newObj: HLobj
- obj: HLobj -> DEobj
- strObj ->: DEobj
- get: [ hdlObj ] putObjHdl: DEobj
- THEN
- THEN
- unlock: HLobj unlock: self ;m
-
-
- \ EXEC: - for every element in the dictionary exec: executes routine with the
- \ associated value and an addr/len pair representing the hashed string as
- \ an argument
-
- \ :m EXEC: { routine -- }
- \ limit: self 0
- \ DO
- \ i select: self
- \ nil?: self
- \ NIF
- \ obj: self -> HLobj
- \ start: HLobj
- \ BEGIN
- \ obj: HLobj -> DEobj
- \ getObj: DEobj get: DEobj
- \ routine execute
- \ unlock: HLobj
- \ next?: HLobj
- \ NUNTIL
- \ unlock: self
- \ THEN
- \ LOOP ;m
-
-
- :m RELEASE:
- release: super limit put: size ;m
-
- :m CLASSINIT:
- limit put: size
- classinit: super ;m
-
- ;class
-
- 25 dictionary SYMTAB
-
- endload
-
- \ Testing
- +echo
-
- 10 dictionary dd
- string s " hello" put: s string t " qqq" put: t
- handle h
-
- ' var newObj: h
- \ h s enter: dd
-
- endload
-
- :class SYMBOLS super( dictionary )
-
- \ QUERY - returns value associated with String in dictionary and FoundFlag. If
- \ string is not found in dictionary, then 0 0 is returned. Needed for SymTab
- \ where 0 is valid value.
-
- :m QUERY: { strObj \ idx HLobj DEobj -- val b }
-
- get: strObj str255 wHash limit: self mod -> idx
- idx select: self
- nil?: self IF 0 false EXIT THEN
- obj: self -> HLobj
- size: HLobj NIF 0 false EXIT THEN
- HLobj strObj searchList: self
- IF
- -> DEobj
- getData: DEobj true
- ELSE
- 0 false
- THEN ;m
-
- ;class
-